package com.jsg.sl651.entity.station;

import com.jsg.sl651.enums.CommunicationMessageType;
import com.jsg.sl651.util.ByteUtil;

/**
 * 遥测站地址
 */
public interface RemoteTelemetryStationAddress {


    public abstract String getMessageHex();

    // 获取报文字节数组
    default byte[] getMessageBytes(CommunicationMessageType type) {
        String messageHex = getMessageHex();
        if (messageHex != null && messageHex.length() == 10) {
            if (type == CommunicationMessageType.ASCII) {
                return ByteUtil.stringToSimpleByteArray(messageHex);
            } else {
                return ByteUtil.toBytes(messageHex);
            }
        } else {
            throw new RuntimeException("遥测站地址格式错误");
        }
    }
}
